package com.asen.commons.core.base.dto;

import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.util.HashMap;
import java.util.Map;

/**
 * 查询DTO基类
 *
 * @author ls
 * @version 1.0
 * @date 2024-04-09
 */
@Data
public class QueryDto<T> {

    private static final long serialVersionUID = 7957886224333584662L;

    @ApiModelProperty(value = "是否分页", position = 1)
    private Boolean isPage = true;

    @ApiModelProperty(value = "当前页码", position = 2, example = "1")
    private Integer pageNum = 1;

    @ApiModelProperty(value = "每页条数", position = 3, example = "10")
    private Integer pageSize = 20;

    @ApiModelProperty(value = "排序字段", position = 4, example = "createTime")
    private String sortName;

    @ApiModelProperty(value = "升序或降序", position = 5, allowableValues = "asc,desc", example = "desc")
    private String order;

    @ApiModelProperty(value = "汇总列（多列之间以逗号分隔）", position = 6)
    private String collectBy;

    @ApiModelProperty(value = "升序字段（多列之间以逗号分隔）", position = 7)
    private String orderByAsc;

    @ApiModelProperty(value = "降序字段（多列之间以逗号分隔）", position = 8)
    private String orderByDesc;

    @ApiModelProperty(value = "数据参数（参数属性默认全匹配查询）", position = 9)
    private T data;

    @ApiModelProperty(value = "扩展参数（参数属性按比较关键字匹配查询）", position = 10)
    private Map<String, Object> params = new HashMap<String, Object>();

    /**
     * 根据key获取参数
     *
     * @param key
     * @return
     */
    public Object getParamsField(String key) {
        return this.params.get(key);
    }

    /**
     * 设置参数
     *
     * @param key
     * @param value
     */
    public void addParamsField(String key, Object value) {
        this.params.put(key, value);
    }

}
